package com.example.mapper;

import com.example.entity.Travels;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 操作travels相关数据接口
*/
public interface TravelsMapper {

    /**
      * 新增
    */
    int insert(Travels travels);

    /**
      * 删除
    */
    int deleteById(Integer id);

    /**
      * 修改
    */
    int updateById(Travels travels);

    /**
      * 根据ID查询
    */
    @Select("select travels.*, user.name as userName, user.avatar as userAvatar from `travels` " +
            "left join user on travels.user_id = user.id where travels.id = #{id}")
    Travels selectById(Integer id);


    /**
      * 查询所有
    */
    List<Travels> selectAll(Travels travels);


    @Update("update travels set read_count = read_count + 1 where id = #{id}")
    void updateReadCount(Integer id);

}
